var Collections = Collections || {};
(function(){
	Collections.List = function(){
		var head = null;
		var count = 0;
		Collections.List.prototype.addHead = function(object){
			var node = {data:object, next:head};
			head = node;
			count++;
		};
		Collections.List.prototype.addTail = function(object){
			var node = {data:ojbect, next:null};
			var current = head;
			var previous = null;
			while(current){
				previous = current;
				current = current.next;
			}
			if(!previous){			// 链表为空
				head = node;
			} else{
				previous.next = node;
			}
			
			count++;
		};
		Collections.List.prototype.count = function(){
			return count;
		}
		Collections.List.prototype.toArray = function(){
			var array = new Array();
			var current = head;
			while(current){
				array.push(current.data);
				current = current.next;
			}
			return array;
		}
	};
})();
